package org.boot.controller;

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.exception.MemcachedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeoutException;


@RestController
@RequestMapping("/memcached")
public class MemcachedController {

    @Autowired
    private MemcachedClient memcachedClient;

    // http://localhost:9090/memcached/set
    @RequestMapping("/set")
    String set() throws InterruptedException, TimeoutException, MemcachedException {
        memcachedClient.set("value", 0, "MemcachedController");
        return "set";
    }

    @RequestMapping("/get")
    String get() throws InterruptedException, TimeoutException, MemcachedException {
        String v = memcachedClient.get("value");
        return v;
    }
}
